/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bff.slimserver.dao;

import com.bff.bjj.dao.SongDao;
import com.bff.bjj.musicobjects.BJJAlbum;
import com.bff.bjj.musicobjects.BJJArtist;
import com.bff.bjj.musicobjects.BJJGenre;
import com.bff.bjj.musicobjects.BJJSong;
import com.bff.slimserver.utils.ConvertUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bff.slimserver.SlimDatabase;
import org.bff.slimserver.exception.SlimDatabaseException;
import org.bff.slimserver.exception.SlimException;
import org.bff.slimserver.musicobjects.SlimSong;

/**
 *
 * @author Bill
 */
public class SlimServerSongDao implements SongDao {

    private SlimDatabase database;

    @Override
    public int getSongCount() {
        try {
            return database.getSongCount();
        } catch (SlimException ex) {
            Logger.getLogger(SlimServerSongDao.class.getName()).log(Level.SEVERE, null, ex);
        }
        return 0;
    }

    @Override
    public Collection<BJJSong> listSongsForArtist(BJJArtist artist) {
        List<SlimSong> songs = null;
        try {
            songs = new ArrayList<SlimSong>(database.listSongsForArtist(ConvertUtils.convertArtist(artist)));
        } catch (SlimDatabaseException ex) {
            Logger.getLogger(SlimServerSongDao.class.getName()).log(Level.SEVERE, null, ex);
        }

        return ConvertUtils.convertSongs(songs);
    }

    @Override
    public Collection<BJJSong> listSongsForYear(String year) {
        List<SlimSong> songs = null;
        try {
            songs = new ArrayList<SlimSong>(database.listSongsForYear(year));
        } catch (SlimDatabaseException ex) {
            Logger.getLogger(SlimServerSongDao.class.getName()).log(Level.SEVERE, null, ex);
        }

        return ConvertUtils.convertSongs(songs);
    }

    @Override
    public Collection<BJJSong> listSongsForGenre(BJJGenre genre) {
        List<SlimSong> songs = null;
        try {
            songs = new ArrayList<SlimSong>(database.listSongsForGenre(ConvertUtils.convertGenre(genre)));
        } catch (SlimDatabaseException ex) {
            Logger.getLogger(SlimServerSongDao.class.getName()).log(Level.SEVERE, null, ex);
        }

        return ConvertUtils.convertSongs(songs);
    }

    @Override
    public Collection<BJJSong> listSongsForAlbum(BJJAlbum album) {
        List<SlimSong> songs = null;
        try {
        songs = new ArrayList<SlimSong>(database.listSongsForAlbum(ConvertUtils.convertAlbum(album)));
        } catch (SlimDatabaseException ex) {
            Logger.getLogger(SlimServerSongDao.class.getName()).log(Level.SEVERE, null, ex);
        }

        return ConvertUtils.convertSongs(songs);
    }

    @Override
    public BJJSong lookupSong(String songId) {
        return ConvertUtils.convertSong(database.lookupSong(songId));
    }
}
